<?PHP

$group = $_POST['group'];
$title = $_POST['title'];
$gallery = $_POST['gallery'];
$counter = $_POST['counter'];
$size = $_POST['size'];

if ($gallery == "true") {
	$target_path = "uploads".$size."/".$group."_-_".$title."/";
	$target_name = $counter."_".basename( $_FILES['Filedata']['name']); 
} else {
	$target_path = "uploads".$size."/".$group."/";
	
	$target_name = basename( $_FILES['Filedata']['name']);
	$ext = strtolower(strrchr($target_name, '.'));	
	$target_name = $group."_-_".$title.$ext; 
}
if(!is_dir($target_path)) mkdir($target_path, 0777); 


if(move_uploaded_file($_FILES['Filedata']['tmp_name'], $target_path.$target_name)) 
{
     echo "The file ". basename( $_FILES['Filedata']['name']). " has been uploaded";
} 
else
{
     echo "There was an error uploading the file, please try again!";
}
?>
